package com.wmlt.service.impl;

import com.wmlt.dao.OrderDao;
import com.wmlt.dao.impl.OrderDaoImpl;
import com.wmlt.entity.Order;
import com.wmlt.service.OrderService;
import com.wmlt.util.JdbcUtil;

import java.sql.Connection;
import java.sql.SQLException;

public class OrderServiceImpl implements OrderService {
    OrderDao orderDao=new OrderDaoImpl();
    Connection connection = null;
    int result=0;
    @Override
    public int inserOrder(Order order) {
        connection = JdbcUtil.getConnection();
        try {
            connection.setAutoCommit(false);//设置手动提交事物
            result = orderDao.inserOrder(order);
            connection.commit();
        } catch (Exception e) {
            e.printStackTrace();
            try {
                connection.rollback();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }

        } finally {
            JdbcUtil.close(null, null, connection);
        }
        return result;
    }

    @Override
    public int queryOrderStatus(String orderId) {
        return orderDao.queryOrderStatus(orderId);
    }
}